//
//  MicroHeader.h
//  MateAdv
//
//  Created by 茶 on 2023/9/8.
//

#ifndef MicroHeader_h
#define MicroHeader_h

#define YYModelSynthCoderAndHash \
- (void)encodeWithCoder:(NSCoder *)aCoder { [self yy_modelEncodeWithCoder:aCoder]; } \
- (id)initWithCoder:(NSCoder *)aDecoder { return [self yy_modelInitWithCoder:aDecoder]; } \
- (id)copyWithZone:(NSZone *)zone { return [self yy_modelCopy]; } \
- (NSUInteger)hash { return [self yy_modelHash]; } \
- (BOOL)isEqual:(id)object { return [self yy_modelIsEqual:object]; } \
- (NSString *)description { return [self yy_modelDescription]; }

/**
 *  自定义颜色宏
 */
#ifndef CAColor
#define CAColor(str) [UIColor colorWithHexString:str]
#endif

#define CAMainColor CAColor(@"#FF0071")
#define CANib(name) [UINib nibWithNibName:name bundle:[NSBundle mainBundle]]


//获取本地对象（系统）
#define CAUserObj(key) [[NSUserDefaults standardUserDefaults] objectForKey:key]
#define CAUserBool(key) [[NSUserDefaults standardUserDefaults] boolForKey:key]
#define CAUserInteger(key) [[NSUserDefaults standardUserDefaults] integerForKey:key]

//字符串是否为空
#define CAStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//数组是否为空
#define CAArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
//字典是否为空
#define CADictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys.count == 0)

#define CAMainBackColor [UIColor colorWithGradientStyle:UIGradientStyleTopToBottom withFrame:self.view.frame andColors:@[CAColor(@"#FF0071"), CAColor(@"#FF74B0")]]

#define CAString(key) NSLocalizedString(key, nil)
/**
 *  判断block存在后执行
 */
#ifndef CABlock
#define CABlock(_b_, ...) if(_b_){_b_(__VA_ARGS__);}
#endif

/**** 数据判空 ****/
//字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//数组是否为空
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
//字典是否为空
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
//是否是空对象
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))

/**** 常用缩写 ****/
#define kApplication            [UIApplication sharedApplication]
#define kKeyWindow              [UIApplication sharedApplication].keyWindow
#define kAppDelegate            [UIApplication sharedApplication].delegate
#define kUserDefaults           [NSUserDefaults standardUserDefaults]
#define kNotifCenter            [NSNotificationCenter defaultCenter]
#define kUserModel              [CAUserManager sharedInstance]

/**
 CAStrongify
 CAStrongify用来解除循环引用
 */
#ifndef CAWeakify
#if DEBUG
#if __has_feature(objc_arc)
#define CAWeakify(object) __weak __typeof__(object) weak##_##object = object
#else
#define CAWeakify(object) __block __typeof__(object) block##_##object = object
#endif
#else
#if __has_feature(objc_arc)
#define CAWeakify(object) __weak __typeof__(object) weak##_##object = object
#else
#define CAWeakify(object) __block __typeof__(object) block##_##object = object
#endif
#endif
#endif

#ifndef CAStrongify
#if DEBUG
#if __has_feature(objc_arc)
#define CAStrongify(object) __typeof__(object) object = weak##_##object
#else
#define CAStrongify(object) __typeof__(object) object = block##_##object
#endif
#else
#if __has_feature(objc_arc)
#define CAStrongify(object) __typeof__(object) object = weak##_##object
#else
#define CAStrongify(object) __typeof__(object) object = block##_##object
#endif
#endif
#endif

#endif /* MicroHeader_h */
